﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Data.SqlClient;
using System.Data;

public partial class Main_Reports_Accounts_VoucherCount : System.Web.UI.Page
{
    Double TotalVoucherCount = 0;
    Datautility du = new Datautility();
    protected void Page_Load(object sender, EventArgs e)
    {
        if (Session["Userid"] == null)
        {
            Response.Redirect("~/SessionExpired.aspx");
        }
        if (!IsPostBack)
        {
            string FinYear = Session["FinYear"].ToString();
            string LastYear = (Convert.ToInt32(Session["FinYear"].ToString()) + 1).ToString();

            lblHeading.Text = "Number Of Voucher Entries in Financial Year  " + FinYear + "-" + LastYear;
            lblCompanyName.Text = Session["CompName"].ToString();
            getVoucherCount(FinYear);
        }
    }
    protected void getVoucherCount(string finyear)
    {

        if (finyear != string.Empty)
        {
            SqlParameter[] pr = { new SqlParameter("@FINYEAR", finyear) };
            DataTable dt = du.getdatausingprocedure("USP_ACC_GetVoucherCount", pr);

            grdDisplay.DataSource = dt;
            grdDisplay.DataBind();
            if (grdDisplay.Rows.Count > 0)
            {
                grdDisplay.UseAccessibleHeader = true;
               
                grdDisplay.HeaderRow.TableSection = TableRowSection.TableHeader;

            }

        }

    }

    protected void grddisplay_RowDataBound(object sender, GridViewRowEventArgs e)
    {
        if (e.Row.RowType == DataControlRowType.DataRow)
        {
            if (e.Row.Cells[2].Text != string.Empty)
            {
                TotalVoucherCount += Convert.ToDouble(e.Row.Cells[2].Text);
            }
            if (Convert.ToDouble(e.Row.Cells[2].Text) == 0)
            {
                e.Row.Cells[2].Text = " - ";
            }

        }

        if (e.Row.RowType == DataControlRowType.Footer)
        {
            e.Row.Cells[1].Text = "Total";
            e.Row.Cells[2].Text = TotalVoucherCount.ToString();
            e.Row.HorizontalAlign = HorizontalAlign.Right;
            e.Row.Font.Bold = true;

        }


    }
}
